<?php
/* @var $this \yii\web\View */
/* @var $dataProvider */
$levelList = \common\models\Level::getList();
?>
<div class="row">
    <div class="box">
        <?php
        echo \backend\components\grid\MyGridView::widget([
            'dataProvider' => $dataProvider,
            'columns' => [
                'id',
                'user_name',
                [
                    'attribute' => 'is_forbidden',
                    'value' => function ($model, $key, $index, $column) {
                        return $model->is_forbidden ? '是' : '否';
                    }
                ],
/*                [
                    'attribute' => 'is_locked',
                    'value' => function ($model, $key, $index, $column) {
                        return $model->is_locked ? '是' : '否';
                    }
                ],*/
                [
                    'label' => '角色',
                    'value' => function ($model, $key, $index, $column) {
                        $arr = [];
                        if ($model->roles) {
                            foreach ($model->roles as $role) {
                                $arr[] = $role->title;
                            }
                        }
                        return join(',', $arr);
                    }
                ],
                [
                    'attribute' => 'level',
                    'value' => function ($model) use ($levelList) {
                        return $levelList[$model->level];
                    }
                ],
                [
                    'attribute' => 'relate_id',
                    'value' => function ($model) {
                        return $model->district ? $model->district->name : '';
                    }
                ],
                'create_time',
                [
                    'class' => \backend\components\grid\MyActionColumn::className(),
                    'template' => '{role}{password}{forbid}',
                    'buttons' => [
                        'role' => function ($url, $model, $key) {
                            $options = [
                                'class' => 'btn btn-success btn-sm',
                                'data-pjax' => '0',
                            ];
                            return \yii\bootstrap\Html::a('修改角色', $url, $options);
                        },
                        'password' => function ($url, $model, $key) {
                            $options = [
                                'class' => 'btn btn-success btn-sm',
                                'data-pjax' => '0',
                            ];
                            return \yii\bootstrap\Html::a('修改密码', $url, $options);
                        },
                        'forbid' => function ($url, $model, $key) {
                            if ($model->is_forbidden) {
                                $options = [
                                    'class' => 'btn btn-primary btn-sm',
                                    'data-confirm' => '是否确认解禁',
                                    'data-method' => 'post',
                                    'data-pjax' => '0'
                                ];
                                $label = '解禁';
                            } else {
                                $options = [
                                    'class' => 'btn btn-danger btn-sm',
                                    'data-confirm' => '是否确认禁用',
                                    'data-method' => 'post',
                                    'data-pjax' => '0'
                                ];
                                $label = '禁用';
                            }

                            return \yii\bootstrap\Html::a($label, $url, $options);
                        }
                    ]
                ]
            ]
        ]); ?>

    </div>
</div>
